<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>随手快递</title>
    <link rel="stylesheet" type="text/css" href="../../AUI/css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../font-awesome/css/font-awesome.min.css" />
    <link rel="stylesheet" href="../../myCss/reset.css"/>
    <link rel="stylesheet" href="../../myCss/pullToRefresh.css"/>
    <style>
        .btn-st{
            display: inline-block;
            float: right;
            margin-right: 15px;
            font-family: 微软雅黑;
            font-size: 14px;
        }
        .add-addr{
            color: rgb(243, 121, 18);
            background: rgb(255, 255, 255);
            border: 1px solid #f37912;
            border-radius: 4px;
            height: 45px;
            line-height: 45px;
        }
    </style>
</head>
<body style="overflow-x: hidden">
<header class="aui-bar aui-bar-nav" id="aui-header">
    <a class="aui-btn aui-pull-left" tapmode onclick="location.href='../helpBuy/index.html'">
        <span class="aui-iconfont aui-icon-left"></span>
    </a>
    <div class="aui-title">收货地址</div>
</header>

<div style="margin-top: 45px">
    <ul class="aui-media-list" id="addressUl">
    </ul>
</div>
<div class="aui-bar aui-bar-tab">
    <div class="add-addr" onclick="location.href='addnewaddr.html'">添加新地址</div>
</div>

<script type="text/javascript" src="../../AUI/script/api.js" ></script>
<script src="../../myJs/jquery.js"></script>
<script src="../../myJs/jquery.cookie.js"></script>
<script type="text/javascript" src="../../myJs/index.js" ></script>
<script type="text/javascript">

    $(function(){
         $.ajax({
         type: "post",
         url: '/randomdelivery/userManageController/address',
         data: {},
         datatype: "json",
         success: function (data) {
        	 address(data);
         }

         });
       
    })

   /*  var data= {
        "code": 200,
        "msg": [
                {
                    "userId":2,
                    "contacts": "summy",
                    "contactsPhone": "172615362712",
                    "address": "浙江省杭州市江干区白杨街道",
                    "addressDetails":"fff",
                    "addressId": "1"
                },
                {
                    "userId":22,
                    "contacts": "旧事不挽",
                    "contactsPhone": "172615328372",
                    "address": "北京市天安门",
                    "addressDetails":"fff",
                    "addressId": "2"
                },
                {
                    "userId":332,
                    "contacts": "小天才",
                    "contactsPhone": "198715362712",
                    "address": "浙江省杭州市西湖区",
                    "addressDetails":"fff",
                    "addressId": "3"
                }
            ]

    }
 */
    function address(data){
        $.each(data.msg,function(num,address){
            $("#addressUl").append(' <li style="margin-bottom: 7px;background: #fff" >\
                    <div class="aui-card-list-content-padded">\
                    <div style="float: left">'+address.contacts+'</div><div style="float:right;">'+address.contactsPhone+'</div><br>\
                    <div style="margin-top: 5px">'+address.address+address.addressDetails+'</div>\
                    </div>\
                    <div class="aui-border-t" style="height: 30px;padding-top: 4px">\
                    <div class="btn-st" onclick="del(this)" addressId="'+address.addressId+'"><span class="fa fa-trash-o"></span> 删除</div>\
                    <div class="btn-st" onclick="edit(this)" addressId="'+address.addressId+'"><span class="fa fa-edit" ></span> 编辑</div>\
                    </div>\
                    </li>')
        })
    }

    function edit(node){
        var addressId = node.getAttribute("addressId");
        sessionStorage.setItem("addressId", addressId);
        location.href="change_addr.html";
    }

    function del(node){
        var addressId = node.getAttribute("addressId");
       // alert(addressId);
         $.ajax({
         type: "post",
         url: '/randomdelivery/userManageController/deleteAddress',
         data: {
         addressId:addressId
         },
         datatype: "json",
         success: function (data) {
        	  $.ajax({
        	         type: "post",
        	         url: '192.168.137.93:8080/randomdelivery/userManageController/address',
        	         data: {},
        	         datatype: "json",
        	         success: function (data) {
        	        	 alertmd("删除成功");
        	        	 $("#addressUl").html("");
        	        	 address(data);
        	         }

        	         });
        	 
         }

         });
    }
</script>
</body>
</html>